use python logging to log user ips+time in a file whenever a request comes to the server, this should be done in a custom middleware.

38

import logging

def foo(request):
    x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
    if x_forwarded_for:
        ip = x_forwarded_for.split(',')[0]
    else:
        ip = request.META.get('REMOTE_ADDR')
        
    some_logger = logging.getLogger(__name__)
    some_logger.warning('Your log message... IP:' + ip)

Comments

Submit
0 Comments